﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PolePosition.v3.Desktop.Selectors.Controls
{
    public partial class Inspector : DialogEditBase
    {
        public Inspector()
        {
            InitializeComponent();
            BindLists();
        }

        private void Projects_Load(object sender, EventArgs e)
        {
            
        }

        //private bool m_BindComplete = false;
        //private List<EntityLibrary.ProjectEntity> m_AfterBindingCompleteSelectedProjects = null;

        private bool m_AllowMultiSelect = false;
        [DefaultValue(false)]
        public bool AllowMultiSelect 
        { 
            get
            {
                return m_AllowMultiSelect;   
            }
            set
            {
                m_AllowMultiSelect = value;
            }
        }

        //[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        //public string SelectedInspector
        //{
        //    get { return listSelector1.GetSelectedValueList<int>(); }
        //    set
        //    {
        //        listSelector1.SetSelectedValueList<int>(value);
        //    }
        //}

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public List<EntityLibrary.VendorContactEntity> SelectedInspectors
        {
            get
            {
                return listSelectorInspector.GetSelectedItems<EntityLibrary.VendorContactEntity>();
            }
            set
            {
                //if (!m_BindComplete)
                //{
                //    m_AfterBindingCompleteSelectedProjects = value;
                //    return;
                //}

                if (value != null)
                    listSelectorInspector.SetSelectedItems<EntityLibrary.VendorContactEntity>(value);

            }
        }

        private void BindLists()
        {
            if (Program.UserSelections.VendorSelectedProject == null)
                return;

            if (Program.LoginResult == null)
                return;


            var _Inspectors = from contact in Program.LoginResult.VendorContacts
                              where contact.VendorFK == Program.UserSelections.VendorSelectedProject.VendorFK
                              select contact;


            listSelectorInspector.DisplayMember = EntityLibrary.VendorContactEnumerations.Columns.Name.ToString();
            listSelectorInspector.ValueMember = EntityLibrary.VendorContactEnumerations.Columns.Vendor_ContactId.ToString();

            if (_Inspectors == null)
                listSelectorInspector.DataSource = null;
            else
                listSelectorInspector.DataSource = _Inspectors.ToList();

            listSelectorInspector.SelectNone();
        }
    }
}
